home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / admin / xinetd.2 / xinetd / xinetd.2.1.7-linux.4 / libs / src / sio / events.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-25  |  3.1 KB  |  104 lines

  1. /*
  2.  * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
  3.  * All rights reserved.  The file named COPYRIGHT specifies the terms 
  4.  * and conditions for redistribution.
  5.  */
  6.  
  7.  
  8. /*
  9.  * $Id: events.h,v 8.1 1993/03/13 01:13:58 panos Exp $
  10.  */
  11.  
  12. /*
  13.  * Event codes
  14.  * 
  15.  * We use a 2 letter code so that events that accumulate in a buffer
  16.  * can be displayed as a string
  17.  * We follow the convention that the first event letter is a capitalized
  18.  * and the second letter is in lower case. This allows one to easily
  19.  * recognize events in an event string.
  20.  */
  21.  
  22. /*
  23.  * The ENCODE macro takes 2 characters and creates a short integer
  24.  * The size of the short integer is assumed to be 16-bits.
  25.  * The macro makes sure that regardless of the endianess of the machine,
  26.  * the low order byte contains the 1st character and the high order byte
  27.  * contains the 2nd character.
  28.  */
  29. #ifdef LITTLE_ENDIAN
  30. #define ENCODE( c1, c2 )                    ( (c1) + ( (c2) << 8 ) )
  31. #else        /* BIG_ENDIAN */
  32. #define ENCODE( c1, c2 )                    ( (c2) + ( (c1) << 8 ) )
  33. #endif
  34.  
  35. /*
  36.  * Event codes for SIO interface functions
  37.  * We use the first 2 lettes after the initial 'S'
  38.  */
  39. #define EV_SGETC                        ENCODE( 'G', 'e' )
  40. #define EV_SPUTC                        ENCODE( 'P', 'u' )
  41. #define EV_SREAD                        ENCODE( 'R', 'e' )
  42. #define EV_SWRITE                        ENCODE( 'W', 'r' ) 
  43. #define EV_SRDLINE                    ENCODE( 'R', 'd' )
  44. #define EV_SFETCH                        ENCODE( 'F', 'e' )
  45. #define EV_SUNDO                        ENCODE( 'U', 'n' )
  46. #define EV_SDONE                        ENCODE( 'D', 'o' )
  47. #define EV_SFLUSH                        ENCODE( 'F', 'l' )
  48. #define EV_SCLOSE                        ENCODE( 'C', 'l' )
  49. #define EV_STIE                        ENCODE( 'T', 'i' )
  50. #define EV_SUNTIE                        ENCODE( 'U', 't' )
  51. #define EV_SBUFTYPE                    ENCODE( 'B', 'u' )
  52.  
  53. /*
  54.  * Event codes for internal functions
  55.  * For the __sio_<name> functions we use 'S' and the first letter of <name>
  56.  * For the rest we use the first letter from the first two components of
  57.  * their name, for example for try_memory_mapping we use Tm.
  58.  */
  59. #define EV_SIO_INIT                    ENCODE( 'S', 'i' )
  60. #define EV_SIO_SWITCH                ENCODE( 'S', 's' )
  61. #define EV_SIO_READF                    ENCODE( 'S', 'r' )
  62. #define EV_SIO_WRITEF                ENCODE( 'S', 'w' )
  63. #define EV_SIO_EXTEND_BUFFER        ENCODE( 'S', 'e' )
  64. #define EV_SIO_MORE                    ENCODE( 'S', 'm' )
  65. #define EV_TRY_MEMORY_MAPPING        ENCODE( 'T', 'm' )
  66. #define EV_INITIAL_MAP                ENCODE( 'I', 'm' )
  67. #define EV_MAP_UNIT                    ENCODE( 'M', 'u' )
  68. #define EV_INIT_INPUT_STREAM        ENCODE( 'I', 'i' )
  69. #define EV_INIT_OUTPUT_STREAM        ENCODE( 'I', 'o' )
  70.  
  71. /*
  72.  * The # of entries must be a power of 2
  73.  */
  74. #define EVENT_ENTRIES        512
  75.  
  76. struct events
  77. {
  78.     short next ;
  79.     short start ;
  80.     short *codes ;            /* malloc'ed memory */
  81. } ;
  82.  
  83. typedef struct events events_s ;
  84.  
  85. extern events_s *__sio_events ;
  86.  
  87.  
  88. #define ADD( index, x )                (index) += x ;                                \
  89.                                             (index) &= ( EVENT_ENTRIES - 1 )
  90.  
  91. #define EVENT( fd, code )                                                            \
  92.                     {                                                                        \
  93.                         events_s *evp = &__sio_events[ fd ] ;                    \
  94.                                                                                             \
  95.                         if ( evp->codes != NULL )                                    \
  96.                         {                                                                    \
  97.                             evp->codes[ evp->next ] = code ;                        \
  98.                             ADD( evp->next, 1 ) ;                                    \
  99.                             if ( evp->next == evp->start )                        \
  100.                             { ADD( evp->start, 1 ) ; }                                \
  101.                         }                                                                    \
  102.                     }
  103.  
  104.